package com.javaspeak.concurrency.pattern.application;

import java.math.BigDecimal;

import com.javaspeak.concurrency.pattern.actor.AbstractActor;

/**
 * @author John Dickerson
 */
public class ExceptionActorImpl extends AbstractActor
    implements ExceptionActor {

    @Override
    public void throwExceptionIfAmountDivisableBy_11( Trade trade ) {

        BigDecimal[] result =
            trade.getAmount().divideAndRemainder( new BigDecimal( 11 ) );

        if ( result[ 1 ].compareTo( new BigDecimal( 0 ) ) == 0 ){

            throw new RuntimeException( "Forced Runtime Exception" );
        }
    }

    @Override
    public void throwExceptionIfAmountDivisableBy_13( Trade trade ) {

        BigDecimal[] result =
            trade.getAmount().divideAndRemainder( new BigDecimal( 13 ) );

        if ( result[ 1 ].compareTo( new BigDecimal( 0 ) ) == 0 ){

            throw new RuntimeException( "Forced Runtime Exception" );
        }
    }
}
